<template>
	<view>
		<view class="wrap">
<!--			<view class="u-tabs-box">-->
<!--				<u-tabs-swiper activeColor="#f29100" ref="tabs" :list="list" :current="current" @change="change" :is-scroll="false"-->
<!--				 swiperWidth="750">-->
<!--				</u-tabs-swiper>-->
<!--			</view>-->
			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition" >
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width:  100%;" @scrolltolower="onReachBottom">
						<view class="page-box">
							<view class="order" v-for="(res, index) in dataList" @click="publicityDetail(res.id)" :key="res.id">
								<view class="top">
									<view class="left">
										<u-icon name="volume" :size="30" color="rgb(94,94,94)"></u-icon>
<!--                    <u&#45;&#45;text :text="res.title"></u&#45;&#45;text>-->
										<view class="store" >{{ res.title | ellipsis}}</view>
									</view>
								</view>
								<view class="item">
									<view class="left">
										<image :src="res.image" mode="aspectFill"></image>
									</view>
									<view class="content">
										<view class="title u-line-2">{{ res.content }}</view>
										<view class="delivery-time">发布日期 {{ res.createTime }}</view>
									</view>
								</view>
							</view>
<!--							<u-loadmore :status="loadStatus[0]" bgColor="#f2f2f2"></u-loadmore>-->
              <!-- 没有数据并且没有更多的时候显示为空状态 -->
              <u-empty v-if="!(dataList.length) && status =='nomore'" mode="list" height="280" marginTop="50"></u-empty>
              <!-- 加载更多 -->
              <u-loadmore :status="status" v-if="dataList.length" line icon-color="#028BF7" marginTop="20"/>

						</view>
					</scroll-view>
				</swiper-item>

			</swiper>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderList: [],
				dataList: [],
				list: [{
						name: '进行中'
					},
					{
						name: '已结束'
					}
				],
				current: 0,
				swiperCurrent: 0,
				tabsHeight: 0,
				dx: 0,
				loadStatus: ['loadmore', 'loading', 'nomore'],
        status: 'loadmore',
        limit: 10,
        page: 1,
        totalPage:"",//总页数
				pageOneNum: 0, //进行中的第几页
				pageTwoNum: 0, //已结束的第几页
			};
		},
		onLoad(source) {

		  if(source.type==1){
        this.initCommunityActivity()
      }else{
		    this.initCommunityNew()
      }
			// this.getOrderList(this.page);
			// this.getOrderList(1);
		},
		computed: {

		},
		methods: {

      //初始化社区公告
      initCommunityActivity() {
        let currentCommunity = uni.getStorageSync('current_community');
        if (!currentCommunity) {
          return;
        }
        let params = {
          type:1,
          page:this.page,
          limit: this.limit,
          communityId:currentCommunity.communityId,
        }

        this.$u.get('/new/new/publicity/miniPage',params).then(res=>{
          // this.dataList = res.data.list
          let data = res.data;
          this.dataList.push(...data.list);//在列表后面新增新获取的数据
          this.totalPage = data.total;//获取数据总页数
        })

      },
      initCommunityNew() {
        let currentCommunity = uni.getStorageSync('current_community');
        if (!currentCommunity) {
          return;
        }
        let params = {
          type:2,
          page:this.page,
          limit: this.limit,
          communityId:currentCommunity.communityId,
        }

        this.$u.get('/new/new/publicity/miniPage',params).then(res=>{
          // this.dataList = res.data.list
          let data = res.data;
          this.dataList.push(...data.list);//在列表后面新增新获取的数据
          this.totalPage = data.total;//获取数据总页数
        })

      },
      publicityDetail(id){
        this.$u.route({
          url:'pages/index/publicity/publicityDetail',
          params:{
            id:id
          }
        })
      },

      onReachBottom() {
        // 如果当前页数大于等于总页数，状态修改为没有更多了，不再继续往下执行代码
        if(this.page >= this.totalPage) {
          this.status = 'nomore';
          return;
        } ;
        this.status = 'loading';//状态改为加载中
        this.page = ++ this.page;//页面新增一页
        this.initCommunityActivity();//修改页数后，重新获取数据
      },
      reachBottom() {
				// 此tab为空数据
				if (this.current != 2) {
					this.loadStatus.splice(this.current, 1, "loading")
					setTimeout(() => {
						this.getOrderList(this.current);
					}, 1200);
				}
			},
			// 页面数据
			getOrderList(idx) {
				// for (let i = 0; i < 5; i++) {
				// 	let index = this.$u.random(0, this.dataList.length - 1);
				// 	let data = JSON.parse(JSON.stringify(this.dataList[index]));
				// 	data.id = this.$u.guid();
				// 	this.orderList[idx].push(data);
				// }
        this.initCommunityActivity()
        console.log(this.dataList)
				if (idx === 0) {
					//获取进行中的数据
					console.log('当前是 %d 个tab页的第 %d 页数据',idx,this.pageOneNum)
					this.pageOneNum++;
				} else {

					console.log('当前是 %d 个tab页的第 %d 页数据',idx,this.pageTwoNum)
					this.pageTwoNum++;
				}

				this.loadStatus.splice(this.current, 1, "loadmore")
			},

			// tab栏切换
			change(index) {
				console.log('当前tab索引', index)
				this.swiperCurrent = index;
				this.getOrderList(index);
			},
			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			}
		}
	};
</script>

<style>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f2f2f2;
	}

	/* #endif */
</style>

<style lang="scss" scoped>
	.order {
		width: 710rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 28rpx;

		.top {
			display: flex;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;

				.store {
					margin: 0 10rpx;
					font-size: 32rpx;
					font-weight: bold;
				}
			}

			.right {
				color: $u-type-warning-dark;
			}
		}

		.item {
			display: flex;
			margin: 20rpx 0 0;

			.left {
				margin-right: 20rpx;

				image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 10rpx;
				}
			}

			.content {
				.title {
					font-size: 28rpx;
					line-height: 50rpx;
				}

				.type {
					margin: 10rpx 0;
					font-size: 24rpx;
					color: $u-tips-color;
				}

				.delivery-time {
					margin-top: 100rpx;
					font-size: 24rpx;
				}
			}

			.right {
				margin-left: 10rpx;
				padding-top: 20rpx;
				text-align: right;

				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}

				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
		}

		.total {
			margin-top: 20rpx;
			text-align: right;
			font-size: 24rpx;

			.total-price {
				font-size: 32rpx;
			}
		}

		.bottom {
			display: flex;
			margin-top: 40rpx;
			padding: 0 10rpx;
			justify-content: space-between;
			align-items: center;

			.btn {
				line-height: 52rpx;
				width: 160rpx;
				border-radius: 26rpx;
				border: 2rpx solid $u-border-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-type-info-dark;
			}

			.evaluate {
				color: $u-type-warning-dark;
				border-color: $u-type-warning-dark;
			}
		}
	}

	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;

		image {
			width: 164rpx;
			height: 164rpx;
			border-radius: 50%;
			margin-bottom: 20rpx;
		}

		.tips {
			font-size: 24rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.btn {
			margin: 80rpx auto;
			width: 200rpx;
			border-radius: 32rpx;
			line-height: 64rpx;
			color: #ffffff;
			font-size: 26rpx;
			background-image: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
		}
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}
</style>
